package com.bank.user.controller;

import com.bank.common.commonUtil.AuthContextHolderUtil;
import com.bank.model.entity.Account;
import com.bank.model.vo.account.AccountUpdatePasswordVo;
import com.bank.model.vo.account.AccountVo;
import com.bank.user.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Cejay1314
 * @version 1.0
 * @create 2023/3/27 16:32
 */
@RestController
@RequestMapping(value = "/user/account")
public class AccountController {
    @Autowired
    AccountService accountService;

    @PostMapping("/create")
    public void createAccount(@RequestBody AccountUpdatePasswordVo accountUpdatePasswordVo, HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        accountService.createAccount(accountUpdatePasswordVo,userId);
    }
    @GetMapping("/query/vo")
    List<AccountVo> getAccountsVo(HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        return accountService.getAccountsVo(userId);
    }
    @GetMapping("/query")
    List<Account> getAccounts(HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        return accountService.getAccounts(userId);
    }
    @GetMapping("/query/id")
    List<Account> getAccounts(@RequestParam Long userId){
        return accountService.getAccounts(userId);
    }
    @PostMapping("/query/one")
    Account getAccount(@RequestParam String accountId){
        return accountService.getAccount(accountId);
    }
    @PostMapping("/update")
    void updataAccount(@RequestBody Account account){
        accountService.updataAccount(account);
    }

    //    删除账户
    @PostMapping("/del")
    void delAccount(@RequestBody AccountUpdatePasswordVo accountUpdatePasswordVo,HttpServletRequest httpServletRequest){
        Long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        accountService.delAccount(accountUpdatePasswordVo,userId);
    }

}
